package 笔试记录.M9day7同程;

public class 鸡兔同笼问题 {
    public int[] chickenAndRabbits (int heads, int feet) {
        // write code here
        int chicken = 0;
        //用鸡头来卡兔子头
        for (; chicken <= heads; chicken++) {
            if(2 * chicken + 4 * (heads - chicken) == feet){
                return new int[]{chicken,heads - chicken};
            }
        }
        return new int[]{-1,-1};
    }
}
